﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BirdCage : SimpleItems_Animator
{
    [SerializeField] CaseManager caseManager;
    [SerializeField] GameObject bird;
    [SerializeField] string birdName="";
    private static GameObject getHandBook_;
    private static GameObject getHandBook
    {
        get
        {
            if (getHandBook_==null)
            {
                getHandBook_ = Resources.Load<GameObject>(@"UI\GetHandBook");
            }
            return getHandBook_;
        }
    }

    protected override void OnAnimationEnd()
    {
        base.OnAnimationEnd();
        caseManager.SaveOneBird(birdName);
        Destroy(bird);
        ending = true;
        if (birdName!=null)
        {
            var clo = Instantiate(getHandBook);
            clo.GetComponent<GetHandBook>().handBook.Init(birdName);
        }
    }

    protected override void OnAnimationStart()
    {
        base.OnAnimationStart();
        end = true;
    }

    private bool ending = false;
    private bool end = false;

    public override void Interactive()
    {
        if (end)
        {
            return;
        }
        base.Interactive();
    }
    protected override void FixedUpdate()
    {
        base.FixedUpdate();
        if (ending)
        {
            light.intensity -= Time.fixedDeltaTime * tipLightSpeed;
            if (light.intensity <= 0)
            {
                light.intensity = 0;
                ending = false;
            }
        }
    }

    protected override void OnTriggerStay2D(Collider2D collision)
    {
        if (end)
        {
            return;
        }
        base.OnTriggerStay2D(collision);
    }

}
